package com.kotlin.tsw.usercenter.ui.activity

import android.os.Bundle
import android.view.View
import com.kotlin.tsw.baselibrary.ext.enable
import com.kotlin.tsw.baselibrary.ui.activity.BaseMVPActivity
import com.kotlin.tsw.usercenter.R
import com.kotlin.tsw.usercenter.injection.component.DaggerUserComponent
import com.kotlin.tsw.usercenter.injection.module.UserModule
import com.kotlin.tsw.usercenter.presenter.ForgetPwdPersenter
import com.kotlin.tsw.usercenter.presenter.view.ForgetPwdView
import kotlinx.android.synthetic.main.activity_forget_pwd.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast

class ForgetPwdActivity : BaseMVPActivity<ForgetPwdPersenter>(), ForgetPwdView, View.OnClickListener {

    override fun injectComponent() {
        DaggerUserComponent.builder().activityComponent(activityComponent).userModule(UserModule()).build().inject(this)
        mPresenter.mView = this
    }

    override fun onForgetPwdResult(result: String) {
        toast(result)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_forget_pwd)
        initView()
    }

    private fun initView() {
        mNextBtn.enable(mMobileEt,{isButtonEnable()})
        mNextBtn.enable(mVerifyCodeEt,{isButtonEnable()})
        mNextBtn.setOnClickListener(this)
        mVerifyCodeBtn.setOnClickListener(this)
    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.mNextBtn -> {
//                mPresenter.forgetPwd(mMobileEt.text.toString().trim(), mVerifyCodeEt.text.toString().trim())
                startActivity<ResetPwdActivity>("Mobile" to mMobileEt.text.toString().trim())
            }
            R.id.mVerifyCodeBtn -> {
                mVerifyCodeBtn.requestSendVerifyNumber()
                toast("验证码已发送")
            }
        }
    }
    fun isButtonEnable():Boolean{
        return !mMobileEt.text.isNullOrEmpty()&&
                !mVerifyCodeEt.text.isNullOrEmpty()
    }
}
